package day05;

import java.sql.Time;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Scanner;

public class h3 {
    public static Scanner scanner=new Scanner(System.in);
    public static int money=1000;
    public static String zh="admin";
    public static String mm="admin";
    public static ArrayList<String> Times=new ArrayList<>();    //public static String[] Times=new String[0];
    public static ArrayList<Integer> Money = new ArrayList<>();    //public static int[] Money=new int[0];
    public static void main(String[] args){
        login();
    }
    public static void login(){
        boolean b=true;
        int t=0;
        while (b){
            System.out.print("请输入账号：");
            String admin=scanner.next();
            System.out.print("请输入密码：");
            String password=scanner.next();
            if(zh.equals(admin)&&mm.equals(password)){
                Use();
            }
            else {
                System.out.println("账号密码错误，请重新输入：");
                t++;
            }
            if(t>3){
                System.out.println("密码输入错误次数太多，已退出！");
                break;
            }
        }
    }
    public static void Use(){
        while (true){
            Index();
            int i=scanner.nextInt();
            //if(i==1||i==2||i==3||i==4||i==5){
                switch (i){
                    case 1:
                        FindMoney();
                        break;
                    case 2:
                        InMoney();
                        break;
                    case 3:
                        OutMoney();
                        break;
                    case 4:
                        Search();
                        break;
                    case 5:
                        System.out.println("欢迎再次使用自选ATM取款机，再见！");
                        System.exit(0);
                    default:
                        System.out.println("输入错误，请重新输入");
                }
        }
    }
    public static void Index(){
        System.out.print(
                "欢迎使用自选ATM取款机：\n" +
                "1.查询余额\n" +
                "2.存款(单笔最大限额为10000)\n" +
                "3.取款(单笔最大限额为10000)\n" +
                "4.交易记录\n" +
                "5.退出\n" +
                "请输入你要执行的操作（输入对应编号即可）：");
    }
    public static void FindMoney(){
        System.out.println("当前余额为："+money);
    }
    public static void InMoney(){
        System.out.print("请输入您要存款的金额：");
        int m=scanner.nextInt();
        if(m<=10000){
            money+=m;
            System.out.println("当前余额为："+money);
            Times(m);
        }
        else{
            System.out.println("超出最大存款金额，请重新取款");
            InMoney();
        }
    }
    public static void OutMoney(){
        System.out.print("请输入您要取款的金额：");
        int m=scanner.nextInt();
        if(m<=10000){
            if(money-m<0){
                System.out.println("余额不足");
            }
            else {
                money-=m;
            }
            System.out.println("当前余额为："+money);
            Times(-m);
        }
        else{
            System.out.println("超出最大取款金额，请重新取款");
            OutMoney();
        }
    }
    public static void Times(int m){
/*        LocalDateTime localDateTime= LocalDateTime.now();
        Times= Arrays.copyOf(Times,Times.length+1);
        Times[Times.length-1]= String.valueOf(localDateTime);
        Money=Arrays.copyOf(Money,Money.length+1);
        Money[Money.length-1]=m;

 */
        Times.add(String.valueOf(new Date()));
        Money.add(m);
    }
    public static void Search(){
        for(int i=0;i<Money.size();i++){
            System.out.print("金额："+Money.get(i)+"\t时间："+ Times.get(i)+"\n");
        }
        System.out.println("当前余额为："+money);
    }
}
